<?php $this->_extends(Helper_Store::layout()); ?>
<?php $this->_block('title'); ?><?=_L('shopping_cart').' '._L('checkout')?>- <?=$store['name']?> <?php $this->_endblock(); ?>
<?php $this->_block('head'); ?>

<?php $this->_endblock(); ?>
<?php $this->_block('contents'); ?>
<?php if(isset($cart['goods'])&&count($cart['goods'])):?>
<div id="MainWrap">

<div class="CartWrap" id="log">
  <div class="CartNav clearfix">
    <div class="floatLeft"><img src="<?=$_BASE_DIR;?>statics/cartnav-step3.gif" alt="购物流程--查看购物车" /></div>
    <div class="floatRight"><img src="<?=$_BASE_DIR;?>statics/cartnav-cart.gif"></div>
  </div>
  	<?php if(isset($error)&&count($error)):?>
	<div class="notice"> 
		<?php foreach($error as $e=>$v):
			switch($e){
				case 'goods': echo _L('cart/cart_empty_notice').'<br>'; break;
				case 'payment': echo _L('cart/no_payment').'<br>'; break;
				case 'shipment': echo _L('cart/no_shipment').'<br>'; break;
				case 'ship': _L('cart/ship_error').'<br>';break;
				default: echo _L('has_error').'<br>';break;
			}
		 endforeach;?>
	</div>
	<?php endif;?>


  <form method="post" action="" id="order-create" extra="subOrder">
    <div style="display:none">
      <input name="checkForm" type="checkForm" class="_x_ipt checkForm" autocomplete="off" vtype="checkForm" />
    </div>
    <div class="FormWrap" >
      <h3><?=_L('shipping_address')?></h3>
      <div id="receiver">
        <div class="division" id="checkout-recaddr">
          <table width="100%" border="0" cellpadding="0" cellspacing="0" class="liststyle data">
            <col class="span-5" />
            <col />
            <tbody>
			  <tr>
                <th><em style="color:red">*</em> <?=_L('email')?>：</th>
                <td>
				<input type="text" class="inputstyle _x_ipt" name="email" value="<?=$cart['ship']['email']?>" size="40" /> 
				</td>
              </tr>
			  <tr class="recsave">
                <th> <em style="color:red">*</em><?=_L('member/gender')?>：</th>
                <td><input type="radio" name="gender" value="m" <?php if($cart['ship']['gender']=='m'){echo 'checked=true';}?> /><?=_L('member/male')?>  &nbsp;&nbsp; <input type="radio" name="gender" value="f" <?php if($cart['ship']['gender']=='f'){echo 'checked=true';}?> /><?=_L('member/female')?> </td>
              </tr>
			  <tr>
                <th><em style="color:red">*</em> <?=_L('first_name')?>:</th>
                <td><input type="text" name="firstname" value="<?=$cart['ship']['firstname']?>" size="20" class="inputstyle _x_ipt" />
                    </td>
              </tr>
              <tr>
                <th><em style="color:red">*</em> <?=_L('last_name')?>:</th>
                <td><input type="text" name="lastname" value="<?=$cart['ship']['lastname']?>" size="20" class="inputstyle _x_ipt" />
                    </td>
              </tr>
			  <tr>
                <th><em style="color:red">*</em> <?=_L('phone')?>:</th>
                <td><input type="text" name="phone" value="<?=$cart['ship']['phone']?>" size="20" class="inputstyle _x_ipt" />
                    </td>
              </tr>
			  <tr>
                <th><?=_L('company')?>:</th>
                <td><input type="text" name="company" value="<?=$cart['ship']['company']?>" size="20" class="inputstyle _x_ipt" />
                    </td>
              </tr>
              <tr>
                <th><em style="color:red">*</em> <?=_L('street')?>:</th>
                <td> <input type="text" class="inputstyle _x_ipt" name="street1" value="<?=$cart['ship']['street1']?>" size="40" />
				</td>
              </tr>
			  <tr>
                <th><?=_L('street')?> 2:</th>
                <td> <input type="text" class="inputstyle _x_ipt" name="street2" value="<?=$cart['ship']['street2']?>" size="40" />
				</td>
              </tr>
              <tr>
                <th><em style="color:red">*</em> <?=_L('postalcode')?>：</th>
                <td><input type="text" name="postalcode" value="<?=$cart['ship']['postalcode']?>" size="10" class="inputstyle _x_ipt" /></td>
              </tr>
              
			  
			  
              <tr>
                <th><?=_L('city')?>：</th>
                <td><input type="text" name="cityname" value="<?=$cart['ship']['cityname']?>" size="20" class="inputstyle _x_ipt" /></td>
              </tr>
              <tr>
                <th><?=_L('province')?>：</th>
                <td><input type="text" name="stateorprovince" value="<?=$cart['ship']['stateorprovince']?>" size="20" class="inputstyle _x_ipt" /></td>
              </tr>
			  <tr>
                <th><em style="color:red">*</em> <?=_L('country')?>：</th>
                <td id="checkout-select-area"><span package="mainland" class="span _x_ipt" vtype="area">
                  <?php Q::control('dropdownlist','country',array(
        "items"=>$country_array,
        'value'=>$cart['ship']['country']
    ))->display()?>
                </span></td>
              </tr>
              
            </tbody>
          </table>
        </div>
        <div class="division">
          <table width="100%" border="0" cellpadding="0" cellspacing="0" class="liststyle data">
            <colgroup class="span-5 ColColorGray">
            </colgroup>
            <colgroup class="span-auto">
            </colgroup>
            <tbody>
              <tr>
                <th>  <?=_L('memo')?> ：</th>
                <td colspan="3"><textarea class="inputstyle _x_ipt" name="memo" type="textarea" cols="40" rows="2" vtype="textarea"></textarea></td>
              </tr>
            </tbody>
          </table>
        </div>
      </div>
      <h3><?=_L('order/select_shipping')?></h3>
      <div class="division">
        <div class="body" id="shipping" >
			<div id="shipmenttablenotice">
				<?=_L('order/country_desc')?>
			</div>
			<table width="100%" border="0" cellpadding="0" cellspacing="0" class="liststyle data" id="shipmenttable">
            <colgroup class="span-5 ColColorGray">
            </colgroup>
            <colgroup class="span-auto">
            </colgroup>
            <tbody>
     			<?php if(count($shipments)) foreach($shipments as $shipment):?>
              <tr>
                <th> <?=$shipment->title?> <input type="radio" name="shipment" value="<?=$shipment->id?>" id="shipment_<?=$shipment->id?>" class="toCheck" onclick="javascript:shipmentchecked($(this).attr('cost'))" cost="0" />  </th>
                <td colspan="3" >
				<span style="font-size: 14px;" class="fontcolorRed" id="shipmentfee_<?=$shipment->id?>"></span>
				  </td>
              </tr>
			  <?php endforeach;?>
            </tbody>
          </table>
        </div>
      </div>
      <h3> <?=_L('payment_name')?>
	  <?php /*
	   <?=_L('select_currency')?>  <?php Q::control('dropdownlist','currency',array(
        "items"=> Helper_Array::toHashmap(Store_Currencies::all()->toArray(),'code','title'),
        'value'=> Helper_Currency::using()
    ))->display()
	*/
	?>
	  
      </h3>
      <div class="division">
        <div class="body" id="payment">
          <table width="100%" cellpadding="0" cellspacing="0" class="liststyle data" id="_normal_payment">
            <colgroup class="span-5 ColColorGray">
            </colgroup>
            <colgroup class="span-auto">
            </colgroup>
			
			<?php if(count($payments)) foreach($payments as $payment):?>
				<li><input type="radio" name="payment" value="<?=$payment->payment_id?>" class="toCheck"  /> <?=$payment->payment->title?></li>
			  <tr id="_pay_cod" style="display:none">
				  <th style="text-align:left;"><input type="radio" name="payment" value="<?=$payment->payment_id?>"  class="x-payMethod" />
					  <strong> <?=$payment->payment->title?></strong></th>
				  <td> <?=$payment->payment->desc?></td>
           	  </tr>
			<?php endforeach;?>
			
          </table>
         
        </div>
      </div>
    
    </div>
    <div class="FormWrap" style="background:#F5F4EC; border:1px solid #E5DDC7;">
      <h3><?=_L('cart/your_cart_products')?></h3>
      <div class="division">
        <table width="100%" cellpadding="0" cellspacing="0" class="liststyle">
          <colgroup class="span-auto">
          </colgroup>
          <colgroup class="span-3">
          </colgroup>
          <colgroup class="span-2">
          </colgroup>
          <colgroup class="span-3">
          </colgroup>
          <colgroup class="span-2 ColColorOrange">
          </colgroup>
          <thead>
            <tr>
              <th class="product"><?=_L('goods_name')?></th>
              <th class="number"><?=_L('price')?></th>
              <th class="number"><?=_L('quantity')?></th>
              <th class="price"><?=_L('subtotal')?> </th>
            </tr>
          </thead>
          <tbody>
		  <?php $productamount=0;
			foreach($cart['goods'] as $cartkey=>$sg):
				$g=$goods[$sg['goods_id']];
				$q=$sg['quantity'];
				$total=$q*$sg['price'];
				$productamount+=Helper_currency::conver($total,$sg['currency']);
			?>
            <tr>
              <td class="product;" style="text-align:left;"><?=$sg['title']?>
				</td>
              <td class="cost"> <?=Helper_currency::fetch($sg['price'],$sg['currency'])?></td>
              <td class="number"><?=$sg['quantity']?></td>
              <td class="cost"><?=Helper_currency::fetch($total,$sg['currency'])?></td>
            </tr>
			<?php endforeach;
			$shipcost=0;
			$amount=$productamount;
			?>
          </tbody>
        </table>
      </div>
    </div>
    <div id="amountInfo">
      <table width="100%" cellpadding="0" cellspacing="0" class="liststyle data">
        <col class="span-auto ColColorGray" />
        <col class="span-4 ColColorOrange textright" />
        <tr>
          <th><?=_L('goods_amount')?>：</th>
          <td value="216" class="price"><?=Helper_currency::fetch($productamount, Helper_Currency::using())?></td>
        </tr>
        <tr>
          <th><?=_L('shipping_amount')?>：</th>
          <td value="216" class="price" id="shipcost"><?=Helper_currency::fetch($shipcost)?></td>
        </tr>
        <tr>
          <th><?=_L('order_amount')?>：</th>
          <td><span class="price1" id="amount"><?=Helper_currency::fetch($amount)?></span></td>
        </tr>
      </table>
    </div>
    <div class="CartBtn clearfix">
	  <input type="hidden" name="productamout" id="productamout" value="<?=$productamount?>">
      <input type="hidden" name="fromCart" value="true" />
      <div class="span-auto">
        <input name="button"  type="button" class="actbtn btn-return-checkout" onClick="history.back()" value="Return" />
      </div>
      <div class="span-auto floatRight last">
        <input name="submit" type="submit" class="actbtn btn-order" value=" Confirm " />
      </div>
    </div>
  </form>
  
</div>
<?php else:?>
<p id="cart-none-msg">
<div class="notice">
	<?=_L('cart/cart_empty_notice')?>
</div>
<h3><?=_L('you_can')?>:</h3>
<ul class='list'><li><a href='<?=_url('index')?>'><?=_L('back_index')?></a></li><li><a href='javascript:opener=null;window.close();'><?=_L('close')?></a></li></ul>
</p>
<?php endif;?>
<script language="javascript">

$(document).ready(function(){ 
	shippingfee('<?=$cart['ship']['country']?>');
});
$('#country').change(function(){shippingfee(this.value)});

function shippingfee(country){
	if(country==""){
		$('#shipmenttable').hide();
		$('#shipmenttablenotice').show();
	}else{
		$('#shipmenttable').show();
		$('#shipmenttablenotice').hide();
	}
	shipmentchecked(0);
	$.post("<?=_url('AjaxShippingfeecalculater')?>",{'country':country},function(data){
	   o = eval("("+ data+ ")");
	   for (key in o){
		   if(o[key]==""&&typeof(o[key])=='string'){
			  $('#shipment_'+key).removeAttr('checked');
			  $('#shipment_'+key).attr('disabled','true');
			  $('#shipmentfee_'+key).html("");
		   }else{
		   	  $('#shipment_'+key).removeAttr('checked');
			  $('#shipment_'+key).removeAttr('disabled');
			  $('#shipmentfee_'+key).html(' + '+ currency(o[key],'<?=Helper_Currency::using()?>'));
			  $('#shipment_'+key).attr('cost',o[key]);
		   }
	   }
    }); 
}
function shipmentchecked(shippingcost){
	$('#amount').html(currency(parseFloat(shippingcost)+parseFloat($('#productamout').val()),'<?=Helper_Currency::using()?>'));
	$('#shipcost').html(currency(shippingcost,'<?=Helper_Currency::using()?>'));
}
</script>
<?php $this->_endblock('contents'); ?>
